﻿using SD.ContentSystem.Domain.Entities;
using SD.ContentSystem.Domain.IDomainServices;
using SD.ContentSystem.Domain.Mediators;
using System;
using System.Collections.Generic;

namespace SD.ContentSystem.DomainService.Implements
{
    /// <summary>
    /// 栏目领域服务实现
    /// </summary>
    public class ChannelService : IChannelService
    {
        #region # 依赖注入构造器

        /// <summary>
        /// 仓储中介者
        /// </summary>
        private readonly RepositoryMediator _repMediator;

        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        /// <param name="repMediator">仓储中介者</param>
        public ChannelService(RepositoryMediator repMediator)
        {
            this._repMediator = repMediator;
        }

        #endregion

        #region # 获取栏目下文章条数/页数 —— KeyValuePair<int, int> GetPage(Channel channel)
        /// <summary>
        /// 获取栏目下文章条数/页数
        /// </summary>
        /// <param name="channel">栏目</param>
        /// <returns>栏目下文章条数/页数</returns>
        /// <remarks>KeyValuePair[int, int]，[条数, 页数]</remarks>
        public KeyValuePair<int, int> GetPage(Channel channel)
        {
            int rowCount = this._repMediator.ArticleRep.Count(channel.Number);
            int pageCount = (int)Math.Ceiling(rowCount * 1.0 / channel.PageSize);

            return new KeyValuePair<int, int>(rowCount, pageCount);
        }
        #endregion
    }
}
